# 发送邮件
# 标准邮件需要三个头部信息： From, To, 和 Subject ，每个信息直接使用空行分割
import smtplib
from email.header import Header
from email.mime.text import MIMEText

# 第三方 SMTP 服务
mail_host = "smtp.qq.com"  # 设置服务器
# 发送方用户名/密码(密码为授权码)
mail_user = "564427933@qq.com"  # 用户名
mail_pass = "yygzhpumnkpabehc"  # 口令

receivers = ['564427933@qq.com']  # 接收方用户名

message = MIMEText('Python 邮件发送测试', 'plain', 'utf-8')  # 邮件内容
message['From'] = Header('菜鸟测试', 'utf-8')  # 发件人名称
message['To'] = Header('测试', 'utf-8')  # 收件人名称
message['subject'] = Header('Pythonn SMTP', 'utf-8')  # 标题信息

try:
    smtpObj = smtplib.SMTP()
    smtpObj.connect(mail_host, 25)
    smtpObj.login(mail_user, mail_pass)
    smtpObj.sendmail(mail_user, receivers, message.as_string())
    print("邮件发送成功")
except smtplib.SMTPException:
    print("无法发送邮件")
